// pages/newar/newar.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    modalHidden: true,
    date: '2020-09-01',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarColor({
      backgroundColor: '#ffffff',
      frontColor: '#000000',
    })
    wx.setNavigationBarTitle({
      title: '创建AR活动',
    })
  },
  zhuye(){
    wx.redirectTo({
      url: '../ayeshou/yeshou',
    })
  },

  bindDateChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },
  
  formSubmit: function (e) {
    console.log('form发生了submit事件，携带数据为：', e.detail.value);
    var openid = wx.getStorageSync('openid')
    // console.log(typeof(openid))================验证openid为空
      wx.checkSession({
        success: (res) => {console.log("正常")},
        fail:(res)=>{console.log("登录态失效")}
      })
    var activityName= e.detail.value.activityname
    // var activityDate= e.detail.value.activitydate
    var activityDate= this.data.date
    var activityType= e.detail.value.type
    var storyBackGround= e.detail.value.story
    // var zcco= 'green'
    // var tip1 = this.data.tip1
    // var tip2 = this.data.tip2


    if(activityName==""||activityDate==""||activityType==""||storyBackGround==""){
      wx.showModal({
        cancelColor: 'blue',
          content: '输入不能为空',
          success (res) {
          }
      })
    }
    else{
      wx.login({
        timeout: 10,
      })
      var placemsg = wx.getStorageSync('setplace')
      
      wx.request({
        url: 'https://www.juquduo.com/juquduo/activity/company/create_activity',
        // url:'https://www.xinshengxing.top/uploadsBase',
        data: {
          openid:openid,
          avatar:app.globalData.userInfo.avatarUrl,
          activityName: activityName,
          activityDate:activityDate,
          activityType: activityType,
          storyBackGround: storyBackGround,
        },
        method: 'GET',
        success: function (res) {
          // success
          var canshu = res.data.rowsAffected
          console.log('获取活动id：')
          console.log(res.data)
          if(placemsg.placename=='朝阳公园'){
            wx.navigateTo({
              url: '../cdianwei/dianwei?id='+canshu+'&type='+res.data.is_release,
            })
          }else if(placemsg.placename=='天泽路'){
            wx.navigateTo({
              url: '../cdianweisecond/dianwei?id='+canshu+'&type='+res.data.is_release,
            })
          }else{
            wx.navigateTo({
              url: '../cdianweithree/dianwei?id='+canshu+'&type='+res.data.is_release,
            })
          }
        },
        fail:function(res){
          console.log('没有活动id')
          console.log(res)
        }
      })
      console.log('jieshu')
    }
  },
  //弹窗  
  buttonTap: function() {
    this.setData({
      modalHidden: false
    })
  },
  modalConfirm: function() {
    this.setData({
      modalHidden: true
    })
  },
  modalCandel: function() {
    this.setData({
      modalHidden: true
    })
  },
})